package com.zk.curator.demo;

import com.zk.curator.CreateClientExamples;
import org.apache.curator.framework.CuratorFramework;

/**
 * <h3>partitionjob</h3>
 * <p>zk dmeo</p>
 *
 * @author : hduong
 * @version : 1.0
 * @date : 2019-12-23 17:54
 **/
public class Demo1 {


    //单机版
    public static final String ZOOKEEPERSTRING = "192.168.80.3:2181";
    //zookeeper集群
    public static final String ZOOKEEPERSTRING2 = "192.168.80.3:2181, 192.168.80.4:2184, 192.168.80.5:2185, 192.168.80.6:2186";

    public static void main(String[] args) throws Exception {
        CuratorFramework curatorFramework = null;
        curatorFramework = CreateClientExamples.curatorFramework(ZOOKEEPERSTRING);
        curatorFramework.start();
        //创建节点  只能在存在的节点下创建,并且该节点必须不存在
        //CrudExamples.create(curatorFramework, "/Demo1/", "Demo1".getBytes());//只能在存在的节点 ： 意思必须先创建自定义的根节点才能创建节点
//        CrudExamples.create(curatorFramework, "/Demo1/number12", "Demo1".getBytes());

        //创建临时节点
        CrudExamples.create(curatorFramework, "/Demo1/yibushezhi", "temp1".getBytes());
//        CrudExamples.createEphemeral(curatorFramework, "/Demo1/temp1", "temp1".getBytes());

        //创建临时顺序节点
//        CrudExamples.createEphemeralSequential(curatorFramework, "/Demo1/temp2", "temp2".getBytes());
//        CrudExamples.createEphemeralSequential(curatorFramework, "/Demo1/temp3", "temp3".getBytes());
//        CrudExamples.createEphemeralSequential(curatorFramework, "/Demo1/temp4", "temp4".getBytes());

        //修改节点
//        CrudExamples.setData(curatorFramework, "/Demo1/number12", "update_jiedian".getBytes());

        //异步设置数据
//        CrudExamples.setDataAsync(curatorFramework, "/Demo1/yibushezhi", "异步设置数据".getBytes());


        //删除节点
//        CrudExamples.delete(curatorFramework, "/Demo1/number1");

        //安全保证删除
//        CrudExamples.guaranteeDelete(curatorFramework, "/Demo1/number12");

        if(curatorFramework!=null) {
            curatorFramework.close();
        }
    }



}
